package se.combitech;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;

import javax.enterprise.event.Event;
import javax.inject.Inject;

public class Reader {

	public Reader() {
		System.out.println("Skapar reader");
	}
	
	@Inject
	Event<FileEvent> fileEvent;	

	public void readFile(File file) {

		try (FileReader reader = new FileReader(file);
				BufferedReader buffered = new BufferedReader(reader)) {
			
			String line = null;
			int numberOfLines = 0;
			while((line = buffered.readLine())!=null){
				System.out.println(line);
				numberOfLines++;
			}
			
			fileEvent.fire(new FileEvent(numberOfLines));
			fileEvent.fire(new FileEvent(numberOfLines));
			fileEvent.fire(new FileEvent(numberOfLines));
			fileEvent.fire(new FileEvent(numberOfLines));
			
		} catch (Exception e) {
			System.out.println(e);
		}
	}
}
